<?php
/**
*
* @author Blackpawn blackpawn666@hotmail.com - http://blackpawnsarchives.net
* @co_author GameCharmer admin@gamecharmer.com - http://gaming.gamecharmer.com
* @package Age of Dragons Mod :: ( Game Console Required )
* @version $Id: quests.php 1.1.1 12-26-2009 Blackpawn
* @copyright (c) 2009 Blackpawns Archives
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/

define('GC_MOD', true);
define('IN_PHPBB', true);
define('AOD', true);

$phpbb_root_path =  '../../';
$templates_path = '../../../games/aod/templates/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/mods/game_console/gc_common.' . $phpEx);
include($phpbb_root_path . 'games/aod/common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Set custom language path
$user->set_custom_lang_path($phpbb_root_path.'games/aod/language/');

//load our language file
$user->add_lang('common');

// Now add the phpBB language path
$user->set_custom_lang_path($phpbb_root_path . 'language');

// Load the Game Console language file
$user->add_lang('mods/game_console');

if ($user->data['user_id'] == ANONYMOUS)
{
	login_box('', $user->lang['LOGIN']);
}

if ($user->data['is_bot'])
{
	redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}


// Constants
$quests_page = TRUE;	// Highlights the quests tab
$error_msgs = null;
$pagination_url = append_sid("quests.$phpEx");
$admin = 0;
$new_villagers = 0;
$new_gold = 0;
$new_food = 0;
$new_wood = 0;
$new_iron = 0;
$new_dragoncoins = 0;
$new_exp = 0;
$new_soldiers = 0;
$new_spies = 0;
$new_macemen = 0;
$new_axemen = 0;
$new_spearmen = 0;
$new_swordsmen = 0;
$new_legionnaires = 0;
$new_knights = 0;
$new_slingers = 0;
$new_bowmen = 0;
$new_long_bowmen = 0;
$new_crossbowmen = 0;
$new_light_sword_cavalry = 0;
$new_heavy_sword_cavalry = 0;
$new_light_archer_cavalry = 0;
$new_heavy_archer_cavalry = 0;
$new_paladin = 0;
$new_dragon_knights = 0;
$new_rams = 0;
$new_catapults = 0;
$new_heavy_catapults = 0;
$new_ballistas = 0;
$new_trebuchets = 0;
$new_chimeras = 0;
$new_hydras = 0;
$new_basilisks = 0;
$new_wyverns = 0;
$new_leviathans = 0;
$new_dragons = 0;
$new_land = 0;
$new_farms = 0;
$new_timber_mills = 0;
$new_iron_mines = 0;
$new_gold_mines = 0;
$new_towers = 0;
$new_granaries = 0;
$new_woodsheds = 0;
$new_ironpits = 0;
$new_vaults = 0;
$gold_req = 0;
$food_req = 0;
$wood_req = 0;
$iron_req = 0;
		
// Vars
$cmd = request_var('cmd','');
$qid = request_var('qid', 0);
$start = request_var('start', 0);

// AOD Config
$quests_per_page = $aod_config['quests_per_page'];


// Gather some user info
$user_id = $user->data['user_id'];
$account_status = check_account_status($user_id);
if ($account_status == FALSE)
{
	redirect(append_sid("{$phpbb_root_path}/games/index.$phpEx"));
}

// Fetch kingdom data
$king 							= fetch_kingdom_data($user_id);
$admin_access 					= $king['admin_access'];
$kingdom_sponsor 				= $king['kingdom_sponsor'];
$kingdom_level 					= $king['kingdom_level'];
$kingdom_exp 					= $king['kingdom_exp'];
$kingdom_net 					= $king['kingdom_net'];
$kingdom_villagers 				= $king['kingdom_villagers'];
$kingdom_spies 					= $king['kingdom_spies'];
$kingdom_soldiers 				= $king['kingdom_soldiers'];
$kingdom_macemen 				= $king['kingdom_macemen'];
$kingdom_axemen		 			= $king['kingdom_axemen'];
$kingdom_spearmen 				= $king['kingdom_spearmen'];
$kingdom_swordsmen 				= $king['kingdom_swordsmen'];
$kingdom_legionnaires 			= $king['kingdom_legionnaires'];
$kingdom_knights 				= $king['kingdom_knights'];
$kingdom_slingers 				= $king['kingdom_slingers'];
$kingdom_bowmen 				= $king['kingdom_bowmen'];
$kingdom_long_bowmen 			= $king['kingdom_long_bowmen'];
$kingdom_crossbowmen 			= $king['kingdom_crossbowmen'];
$kingdom_light_sword_cavalry 	= $king['kingdom_light_sword_cavalry'];
$kingdom_heavy_sword_cavalry 	= $king['kingdom_heavy_sword_cavalry'];
$kingdom_light_archer_cavalry 	= $king['kingdom_light_archer_cavalry'];
$kingdom_heavy_archer_cavalry 	= $king['kingdom_heavy_archer_cavalry'];
$kingdom_paladin 				= $king['kingdom_paladin'];
$kingdom_dragon_knights 		= $king['kingdom_dragon_knights'];
$kingdom_rams 					= $king['kingdom_rams'];
$kingdom_catapults 				= $king['kingdom_catapults'];
$kingdom_heavy_catapults 		= $king['kingdom_heavy_catapults'];
$kingdom_ballistas				= $king['kingdom_ballistas'];
$kingdom_trebuchets 			= $king['kingdom_trebuchets'];
$kingdom_chimeras				= $king['kingdom_chimeras'];
$kingdom_hydras					= $king['kingdom_hydras'];
$kingdom_basilisks 				= $king['kingdom_basilisks'];
$kingdom_wyverns 				= $king['kingdom_wyverns'];
$kingdom_leviathans 			= $king['kingdom_leviathans'];
$kingdom_dragons 				= $king['kingdom_dragons'];
$kingdom_farms 					= $king['kingdom_farms'];
$kingdom_timber_mills 			= $king['kingdom_timber_mills'];
$kingdom_iron_mines 			= $king['kingdom_iron_mines'];
$kingdom_gold_mines 			= $king['kingdom_gold_mines'];
$kingdom_towers 				= $king['kingdom_towers'];
$kingdom_granaries 				= $king['kingdom_granaries'];
$kingdom_woodsheds 				= $king['kingdom_woodsheds'];
$kingdom_ironpits 				= $king['kingdom_ironpits'];
$kingdom_vaults 				= $king['kingdom_vaults'];
$kingdom_land 					= fetch_total_land($user_id);
$kingdom_stamina 				= $king['kingdom_stamina'];
$kingdom_gold 					= $king['kingdom_gold'];
$kingdom_food 					= $king['kingdom_food'];
$kingdom_wood 					= $king['kingdom_wood'];
$kingdom_iron 					= $king['kingdom_iron'];

$kingdom_status 				= $king['kingdom_status'];

// Check to see if this user is a admin staff member
if ($user_id == 2 || $admin_access == 1)
{
	$admin = 1;
}

// Check kingdom status to see if this account is frozen
if($kingdom_status == 1)
{
	// Lets make sure the main admin can't be blocked
	if ($user_id <> 2){
		trigger_error($user->lang['FROZEN'] . back_link());
	}
}

// Commands
if($cmd == $user->lang['DO_QUEST'])
{
	$error 						= FALSE;
	$error_msgs 				= null;
	$questdata 					= fetch_quest_data($qid);
	$level_req 					= $questdata['quest_level_req'];
	$net_req 					= $questdata['quest_net_req'];
	$villagers_req 				= $questdata['quest_villagers_req'];
	$spies_req 					= $questdata['quest_spies_req'];
	$soldiers_req			 	= $questdata['quest_soldiers_req'];
	$macemen_req 				= $questdata['quest_macemen_req'];
	$axemen_req 				= $questdata['quest_axemen_req'];
	$spearmen_req 				= $questdata['quest_spearmen_req'];
	$swordsmen_req 				= $questdata['quest_swordsmen_req'];
	$legionnaires_req 			= $questdata['quest_legionnaires_req'];
	$knights_req 				= $questdata['quest_knights_req'];
	$slingers_req 				= $questdata['quest_slingers_req'];
	$bowmen_req 				= $questdata['quest_bowmen_req'];
	$long_bowmen_req 			= $questdata['quest_long_bowmen_req'];
	$crossbowmen_req 			= $questdata['quest_crossbowmen_req'];
	$light_sword_cavalry_req 	= $questdata['quest_light_sword_cavalry_req'];
	$heavy_sword_cavalry_req 	= $questdata['quest_heavy_sword_cavalry_req'];
	$light_archer_cavalry_req 	= $questdata['quest_light_archer_cavalry_req'];
	$heavy_archer_cavalry_req 	= $questdata['quest_heavy_archer_cavalry_req'];
	$paladin_req 				= $questdata['quest_paladin_req'];
	$dragon_knights_req 		= $questdata['quest_dragon_knights_req'];
	$rams_req 					= $questdata['quest_rams_req'];
	$catapults_req 				= $questdata['quest_catapults_req'];
	$heavy_catapults_req 		= $questdata['quest_heavy_catapults_req'];
	$ballistas_req 				= $questdata['quest_ballistas_req'];
	$trebuchets_req 			= $questdata['quest_trebuchets_req'];
	$chimeras_req 				= $questdata['quest_chimeras_req'];
	$hydras_req 				= $questdata['quest_hydras_req'];
	$basilisks_req 				= $questdata['quest_basilisks_req'];
	$wyverns_req 				= $questdata['quest_wyverns_req'];
	$leviathans_req 			= $questdata['quest_leviathans_req'];
	$dragons_req 				= $questdata['quest_dragons_req'];
	$farms_req 					= $questdata['quest_farms_req'];
	$timber_mills_req 			= $questdata['quest_timber_mills_req'];
	$iron_mines_req 			= $questdata['quest_iron_mines_req'];
	$gold_mines_req 			= $questdata['quest_gold_mines_req'];
	$towers_req 				= $questdata['quest_towers_req'];
	$granaries_req 				= $questdata['quest_granaries_req'];
	$woodsheds_req 				= $questdata['quest_woodsheds_req'];
	$ironpits_req 				= $questdata['quest_ironpits_req'];
	$vaults_req 				= $questdata['quest_vaults_req'];
	$land_req 					= $questdata['quest_land_req'];
	$stamina_req 				= $questdata['quest_stamina_req'];
	$gold_req 					= $questdata['quest_gold_req'];
	$food_req 					= $questdata['quest_food_req'];
	$wood_req 					= $questdata['quest_wood_req'];
	$iron_req 					= $questdata['quest_iron_req'];
	$quest_chance 				= $questdata['quest_chance'];

	if($kingdom_level < $level_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LEVEL_REQ'].'<br />';
	}
	
	if($kingdom_net < $net_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_NET_REQ'].'<br />';
	}	
	
	if($kingdom_villagers < $villagers_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_VILLAGERS_REQ'].'<br />';
	}	

	if($kingdom_spies < $spies_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_SPIES_REQ'].'<br />';
	}	

	if($kingdom_soldiers < $soldiers_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_SOLDIERS_REQ'].'<br />';
	}	

	if($kingdom_macemen < $macemen_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_MACEMEN_REQ'].'<br />';
	}	

	if($kingdom_axemen < $axemen_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_AXEMEN_REQ'].'<br />';
	}	

	if($kingdom_spearmen < $spearmen_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_SPEARMEN_REQ'].'<br />';
	}	

	if($kingdom_swordsmen < $swordsmen_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_SWORDSMEN_REQ'].'<br />';
	}	

	if($kingdom_legionnaires < $legionnaires_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LEGIONNAIRES_REQ'].'<br />';
	}	

	if($kingdom_knights < $knights_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_KNIGHTS_REQ'].'<br />';
	}	

	if($kingdom_slingers < $slingers_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_SLINGERS_REQ'].'<br />';
	}	
	
	if($kingdom_bowmen < $bowmen_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_BOWMEN_REQ'].'<br />';
	}	
	
	if($kingdom_long_bowmen < $long_bowmen_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LONG_BOWMEN_REQ'].'<br />';
	}	
	
	if($kingdom_crossbowmen < $crossbowmen_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_CROSS_BOWMEN_REQ'].'<br />';
	}
		
	if($kingdom_light_sword_cavalry < $light_sword_cavalry_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LIGHT_SWORD_CAVALRY_REQ'].'<br />';
	}	
	
	if($kingdom_heavy_sword_cavalry < $heavy_sword_cavalry_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_HEAVY_SWORD_CAVALRY_REQ'].'<br />';
	}	
	
	if($kingdom_light_archer_cavalry < $light_archer_cavalry_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LIGHT_ARCHER_CAVALRY_REQ'].'<br />';
	}	
	
	if($kingdom_heavy_archer_cavalry < $heavy_archer_cavalry_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_HEAVY_ARCHER_CAVALRY_REQ'].'<br />';
	}
		
	if($kingdom_paladin < $paladin_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_PALADIN_REQ'].'<br />';
	}	
	
	if($kingdom_dragon_knights < $dragon_knights_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_DRAGON_KNIGHT_REQ'].'<br />';
	}	

	if($kingdom_rams < $rams_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_RAMS_REQ'].'<br />';
	}	
	
	if($kingdom_catapults < $catapults_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_CATAPULTS_REQ'].'<br />';
	}	
	
	if($kingdom_heavy_catapults < $heavy_catapults_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_HEAVY_CATAPULTS_REQ'].'<br />';
	}	
	
	if($kingdom_ballistas < $ballistas_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_BALLISTAS_REQ'].'<br />';
	}	
	
	if($kingdom_trebuchets < $trebuchets_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_TREBUCHETS_REQ'].'<br />';
	}	
	
	if($kingdom_chimeras < $chimeras_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_CHIMERAS_REQ'].'<br />';
	}	
	
	if($kingdom_hydras < $hydras_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_HYDRAS_REQ'].'<br />';
	}	
	
	if($kingdom_basilisks < $basilisks_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_BASILISKS_REQ'].'<br />';
	}
		
	if($kingdom_wyverns < $wyverns_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_WYVERNS_REQ'].'<br />';
	}	
	
	if($kingdom_leviathans < $leviathans_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LEVIATHANS_REQ'].'<br />';
	}
		
	if($kingdom_dragons < $dragons_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_DRAGONS_REQ'].'<br />';
	}	
	
	if($kingdom_farms < $farms_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_FARMS_REQ'].'<br />';
	}	
	
	if($kingdom_timber_mills < $timber_mills_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_TIMBER_MILLS_REQ'].'<br />';
	}
		
	if($kingdom_iron_mines < $iron_mines_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_IRON_MINES_REQ'].'<br />';		
	}
		
	if($kingdom_gold_mines < $gold_mines_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_GOLD_MINES_REQ'].'<br />';
	}	
	
	if($kingdom_towers < $towers_req) 
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_TOWERS_REQ'].'<br />';
	}	

	if($kingdom_granaries < $granaries_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_GRANARIES_REQ'].'<br />';
	}	
	
	if($kingdom_woodsheds < $woodsheds_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_WOOD_SHEDS_REQ'].'<br />';
	}	
	
	if($kingdom_ironpits < $ironpits_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_IRON_PITS_REQ'].'<br />';
	}	
	
	if($kingdom_vaults < $vaults_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_VAULTS_REQ'].'<br />';
	}	
	
	if($kingdom_land < $land_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_LAND_REQ'].'<br />';
	}	
	
	if($kingdom_stamina < $stamina_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_STAMINA_REQ'].'<br />';
	}		

	if($kingdom_gold < $gold_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_GOLD_REQ'].'<br />';
	}		

	if($kingdom_food < $food_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_FOOD_REQ'].'<br />';
	}		

	if($kingdom_wood < $wood_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_WOOD_REQ'].'<br />';
	}		

	if($kingdom_iron < $iron_req)
	{
		$error = TRUE;
		$error_msgs .= $user->lang['DO_NOT_MEET_IRON_REQ'].'<br />';
	}		
	
	if($error == FALSE)
	{
		$chance = rand(1,100);
		
		if($chance > $quest_chance)
		{

			$quest_min_villagers = $questdata['quest_min_villagers'];
			$quest_max_villagers = $questdata['quest_max_villagers'];
			if($quest_max_villagers > 0)
			{
				$new_villagers .= rand($quest_min_villagers,$quest_max_villagers);
				
				if($kingdom_sponsor == TRUE)
				{
					$new_villagers = ($new_villagers * 2);

				}
				
				if($new_villagers == 1)
				{
					$report_rewards[0] = $new_villagers.' '.$user->lang['VILLAGER'];
				}else{
					$report_rewards[0] = number_format($new_villagers).' '.$user->lang['VILLAGERS'];
				}				
			}
			
			$quest_min_gold = $questdata['quest_min_gold'];
			$quest_max_gold = $questdata['quest_max_gold'];
			if($quest_max_gold > 0)
			{
				$new_gold .= rand($quest_min_gold,$quest_max_gold);
				
				if($kingdom_sponsor == TRUE)
				{
					$new_gold = ($new_gold * 2);

				}

				if($new_gold == 1)
				{
					$report_rewards[1] = $new_gold.' '.$user->lang['UNIT_OF_GOLD'];
				}else{
					$report_rewards[1] = number_format($new_gold).' '.$user->lang['UNITS_OF_GOLD'];
				}								
			}
			
			$quest_min_food = $questdata['quest_min_food'];
			$quest_max_food = $questdata['quest_max_food'];
			if($quest_max_food > 0)
			{
				$new_food .= rand($quest_min_food,$quest_max_food);
				if($kingdom_sponsor == TRUE)
				{
					$new_food = ($new_food * 2);
				}

				if($new_food == 1)
				{
					$report_rewards[2] = $new_food.' '.$user->lang['UNIT_OF_FOOD'];
				}else{
					$report_rewards[2] = number_format($new_food).' '.$user->lang['UNITS_OF_FOOD'];
				}								
			}	
			
			$quest_min_wood = $questdata['quest_min_wood'];
			$quest_max_wood = $questdata['quest_max_wood'];
			if($quest_max_wood > 0)
			{
				$new_wood .= rand($quest_min_wood,$quest_max_wood);
				if($kingdom_sponsor == TRUE)
				{
					$new_wood = ($new_wood * 2);
				}				

				if($new_wood == 1)
				{
					$report_rewards[3] = $new_wood.' '.$user->lang['UNIT_OF_WOOD'];
				}else{
					$report_rewards[3] = number_format($new_wood).' '.$user->lang['UNITS_OF_WOOD'];
				}			
			}	
			
			$quest_min_iron = $questdata['quest_min_iron'];
			$quest_max_iron = $questdata['quest_max_iron'];
			if($quest_max_iron > 0)
			{
				$new_iron .= rand($quest_min_iron,$quest_max_iron);
				if($kingdom_sponsor == TRUE)
				{
					$new_iron = ($new_iron * 2);
				}				

				if($new_iron == 1)
				{
					$report_rewards[4] = $new_iron.' '.$user->lang['UNIT_OF_IRON'];
				}else{
					$report_rewards[4] = number_format($new_iron).' '.$user->lang['UNITS_OF_IRON'];
				}			
			}	

			
			$quest_min_dragoncoins = $questdata['quest_min_dragoncoins'];
			$quest_max_dragoncoins = $questdata['quest_max_dragoncoins'];
			if($quest_max_dragoncoins > 0)
			{
				$new_dragoncoins .= rand($quest_min_dragoncoins,$quest_max_dragoncoins);
				if($kingdom_sponsor == TRUE)
				{
					$new_dragoncoins = ($new_dragoncoins * 2);
				}				

				if($new_dragoncoins == 1)
				{
					$report_rewards[5] = $new_dragoncoins.' '.$user->lang['DRAGON_COIN'];
				}else{
					$report_rewards[5] = number_format($new_dragoncoins).' '.$user->lang['DRAGON_COINS'];
				}			
			}		  

			$quest_min_exp = $questdata['quest_min_exp'];
			$quest_max_exp = $questdata['quest_max_exp'];
			if($quest_max_exp > 0)
			{
				$new_exp .= rand($quest_min_exp,$quest_max_exp);
				if($kingdom_sponsor == TRUE)
				{
					$new_exp = ($new_exp * 2);
				}				

				if($new_exp == 1)
				{
					$report_rewards[6] = $new_exp.' '.$user->lang['EXP'];
				}else{
					$report_rewards[6] = number_format($new_exp).' '.$user->lang['EXPS'];
				}			
			}		  

			$quest_min_soldiers = $questdata['quest_min_soldiers'];
			$quest_max_soldiers = $questdata['quest_max_soldiers'];
			if($quest_max_soldiers > 0)
			{
				$new_soldiers .= rand($quest_min_soldiers,$quest_max_soldiers);
				if($kingdom_sponsor == TRUE)
				{
					$new_soldiers = ($new_soldiers * 2);
				}				

				if($new_soldiers == 1)
				{
					$report_rewards[7] = $new_soldiers.' '.$user->lang['SOLDIER'];
				}else{
					$report_rewards[7] = number_format($new_soldiers).' '.$user->lang['SOLDIERS'];
				}			
			}

			$quest_min_spies = $questdata['quest_min_spies'];
			$quest_max_spies = $questdata['quest_max_spies'];
			if($quest_max_spies > 0)
			{
				$new_spies .= rand($quest_min_spies,$quest_max_spies);
				if($kingdom_sponsor == TRUE)
				{
					$new_spies = ($new_spies * 2);
				}				

				if($new_spies == 1)
				{
					$report_rewards[8] = $new_spies.' '.$user->lang['SPY'];
				}else{
					$report_rewards[8] = number_format($new_spies).' '.$user->lang['SPIES'];
				}			
			}

			$quest_min_macemen = $questdata['quest_min_macemen'];
			$quest_max_macemen = $questdata['quest_max_macemen'];
			if($quest_max_macemen > 0)
			{
				$new_macemen .= rand($quest_min_macemen,$quest_max_macemen);
				if($kingdom_sponsor == TRUE)
				{
					$new_macemen = ($new_macemen * 2);
				}				

				if($new_macemen == 1)
				{
					$report_rewards[9] = $new_macemen.' '.$user->lang['MACEMAN'];
				}else{
					$report_rewards[9] = number_format($new_macemen).' '.$user->lang['MACEMEN'];
				}			
			}						

			$quest_min_axemen = $questdata['quest_min_axemen'];
			$quest_max_axemen = $questdata['quest_max_axemen'];
			if($quest_max_axemen > 0)
			{
				$new_axemen .= rand($quest_min_axemen,$quest_max_axemen);
				if($kingdom_sponsor == TRUE)
				{
					$new_axemen = ($new_axemen * 2);
				}				

				if($new_axemen == 1)
				{
					$report_rewards[10] = $new_axemen.' '.$user->lang['AXEMAN'];
				}else{
					$report_rewards[10] = number_format($new_axemen).' '.$user->lang['AXEMEN'];
				}			
			}

			$quest_min_spearmen = $questdata['quest_min_spearmen'];
			$quest_max_spearmen = $questdata['quest_max_spearmen'];
			if($quest_max_spearmen > 0)
			{
				$new_spearmen .= rand($quest_min_spearmen,$quest_max_spearmen);
				if($kingdom_sponsor == TRUE)
				{
					$new_spearmen = ($new_spearmen * 2);
				}				

				if($new_spearmen == 1)
				{
					$report_rewards[11] = $new_spearmen.' '.$user->lang['SPEARMAN'];
				}else{
					$report_rewards[11] = number_format($new_spearmen).' '.$user->lang['SPEARMEN'];
				}			
			}

			$quest_min_swordsmen = $questdata['quest_min_swordsmen'];
			$quest_max_swordsmen = $questdata['quest_max_swordsmen'];
			if($quest_max_swordsmen > 0)
			{
				$new_swordsmen .= rand($quest_min_swordsmen,$quest_max_swordsmen);
				if($kingdom_sponsor == TRUE)
				{
					$new_swordsmen = ($new_swordsmen * 2);
				}				

				if($new_swordsmen == 1)
				{
					$report_rewards[12] = $new_swordsmen.' '.$user->lang['SWORDSMAN'];
				}else{
					$report_rewards[12] = number_format($new_swordsmen).' '.$user->lang['SWORDSMEN'];
				}			
			}			

			$quest_min_legionnaires = $questdata['quest_min_legionnaires'];
			$quest_max_legionnaires = $questdata['quest_max_legionnaires'];
			if($quest_max_legionnaires > 0)
			{
				$new_legionnaires .= rand($quest_min_legionnaires,$quest_max_legionnaires);
				if($kingdom_sponsor == TRUE)
				{
					$new_legionnaires = ($new_legionnaires * 2);
				}				

				if($new_legionnaires == 1)
				{
					$report_rewards[13] = $new_legionnaires.' '.$user->lang['LEGIONNAIRE'];
				}else{
					$report_rewards[13] = number_format($new_legionnaires).' '.$user->lang['LEGIONNAIRES'];
				}			
			}						

			$quest_min_knights = $questdata['quest_min_knights'];
			$quest_max_knights = $questdata['quest_max_knights'];
			if($quest_max_knights > 0)
			{
				$new_knights .= rand($quest_min_knights,$quest_max_knights);
				if($kingdom_sponsor == TRUE)
				{
					$new_knights = ($new_knights * 2);
				}				

				if($new_knights == 1)
				{
					$report_rewards[14] = $new_knights.' '.$user->lang['KNIGHT'];
				}else{
					$report_rewards[14] = number_format($new_knights).' '.$user->lang['KNIGHTS'];
				}			
			}						

			$quest_min_slingers = $questdata['quest_min_slingers'];
			$quest_max_slingers = $questdata['quest_max_slingers'];
			if($quest_max_slingers > 0)
			{
				$new_slingers .= rand($quest_min_slingers,$quest_max_slingers);
				if($kingdom_sponsor == TRUE)
				{
					$new_slingers = ($new_slingers * 2);
				}				

				if($new_slingers == 1)
				{
					$report_rewards[15] = $new_slingers.' '.$user->lang['SLINGER'];
				}else{
					$report_rewards[15] = number_format($new_slingers).' '.$user->lang['SLINGERS'];
				}			
			}

			$quest_min_bowmen = $questdata['quest_min_bowmen'];
			$quest_max_bowmen = $questdata['quest_max_bowmen'];
			if($quest_max_bowmen > 0)
			{
				$new_bowmen .= rand($quest_min_bowmen,$quest_max_bowmen);
				if($kingdom_sponsor == TRUE)
				{
					$new_bowmen = ($new_bowmen * 2);
				}				

				if($new_bowmen == 1)
				{
					$report_rewards[16] = $new_bowmen.' '.$user->lang['BOWMAN'];
				}else{
					$report_rewards[16] = number_format($new_bowmen).' '.$user->lang['BOWMEN'];
				}			
			}			

			$quest_min_long_bowmen = $questdata['quest_min_long_bowmen'];
			$quest_max_long_bowmen = $questdata['quest_max_long_bowmen'];
			if($quest_max_long_bowmen > 0)
			{
				$new_long_bowmen .= rand($quest_min_long_bowmen,$quest_max_long_bowmen);
				if($kingdom_sponsor == TRUE)
				{
					$new_long_bowmen = ($new_long_bowmen * 2);
				}				

				if($new_long_bowmen == 1)
				{
					$report_rewards[17] = $new_long_bowmen.' '.$user->lang['LONG_BOWMAN'];
				}else{
					$report_rewards[17] = number_format($new_long_bowmen).' '.$user->lang['LONG_BOWMEN'];
				}			
			}

			$quest_min_crossbowmen = $questdata['quest_min_crossbowmen'];
			$quest_max_crossbowmen = $questdata['quest_max_crossbowmen'];
			if($quest_max_crossbowmen > 0)
			{
				$new_crossbowmen .= rand($quest_min_crossbowmen,$quest_max_crossbowmen);
				if($kingdom_sponsor == TRUE)
				{
					$new_crossbowmen = ($new_crossbowmen * 2);
				}				

				if($new_crossbowmen == 1)
				{
					$report_rewards[18] = $new_crossbowmen.' '.$user->lang['CROSS_BOWMAN'];
				}else{
					$report_rewards[18] = number_format($new_crossbowmen).' '.$user->lang['CROSS_BOWMEN'];
				}			
			}			

			$quest_min_light_sword_cavalry = $questdata['quest_min_light_sword_cavalry'];
			$quest_max_light_sword_cavalry = $questdata['quest_max_light_sword_cavalry'];
			if($quest_max_light_sword_cavalry > 0)
			{
				$new_light_sword_cavalry .= rand($quest_min_light_sword_cavalry,$quest_max_light_sword_cavalry);
				if($kingdom_sponsor == TRUE)
				{
					$new_light_sword_cavalry = ($new_light_sword_cavalry * 2);
				}				

				if($new_light_sword_cavalry == 1)
				{
					$report_rewards[19] = $new_light_sword_cavalry.' '.$user->lang['LIGHT_SWORD_CAVALRY'];
				}else{
					$report_rewards[19] = number_format($new_light_sword_cavalry).' '.$user->lang['LIGHT_SWORD_CAVALRY'];
				}			
			}			

			$quest_min_heavy_sword_cavalry = $questdata['quest_min_heavy_sword_cavalry'];
			$quest_max_heavy_sword_cavalry = $questdata['quest_max_heavy_sword_cavalry'];
			if($quest_max_heavy_sword_cavalry > 0)
			{
				$new_heavy_sword_cavalry .= rand($quest_min_heavy_sword_cavalry,$quest_max_heavy_sword_cavalry);
				if($kingdom_sponsor == TRUE)
				{
					$new_heavy_sword_cavalry = ($new_heavy_sword_cavalry * 2);
				}				

				if($new_heavy_sword_cavalry == 1)
				{
					$report_rewards[20] = $new_heavy_sword_cavalry.' '.$user->lang['HEAVY_SWORD_CAVALRY'];
				}else{
					$report_rewards[20] = number_format($new_heavy_sword_cavalry).' '.$user->lang['HEAVY_SWORD_CAVALRY'];
				}			
			}			

			$quest_min_light_archer_cavalry = $questdata['quest_min_light_archer_cavalry'];
			$quest_max_light_archer_cavalry = $questdata['quest_max_light_archer_cavalry'];
			if($quest_max_light_archer_cavalry > 0)
			{
				$new_light_archer_cavalry .= rand($quest_min_light_archer_cavalry,$quest_max_light_archer_cavalry);
				if($kingdom_sponsor == TRUE)
				{
					$new_light_archer_cavalry = ($new_light_archer_cavalry * 2);
				}				

				if($new_light_archer_cavalry == 1)
				{
					$report_rewards[21] = $new_light_archer_cavalry.' '.$user->lang['LIGHT_ARCHER_CAVALRY'];
				}else{
					$report_rewards[21] = number_format($new_light_archer_cavalry).' '.$user->lang['LIGHT_ARCHER_CAVALRY'];
				}			
			}			

			$quest_min_heavy_archer_cavalry = $questdata['quest_min_heavy_archer_cavalry'];
			$quest_max_heavy_archer_cavalry = $questdata['quest_max_heavy_archer_cavalry'];
			if($quest_max_heavy_archer_cavalry > 0)
			{
				$new_heavy_archer_cavalry .= rand($quest_min_heavy_archer_cavalry,$quest_max_heavy_archer_cavalry);
				if($kingdom_sponsor == TRUE)
				{
					$new_heavy_archer_cavalry = ($new_heavy_archer_cavalry * 2);
				}				

				if($new_heavy_archer_cavalry == 1)
				{
					$report_rewards[22] = $new_heavy_archer_cavalry.' '.$user->lang['HEAVY_ARCHER_CAVALRY'];
				}else{
					$report_rewards[22] = number_format($new_heavy_archer_cavalry).' '.$user->lang['HEAVY_ARCHER_CAVALRY'];
				}			
			}			

			$quest_min_paladin = $questdata['quest_min_paladin'];
			$quest_max_paladin = $questdata['quest_max_paladin'];
			if($quest_max_paladin > 0)
			{
				$new_paladin .= rand($quest_min_paladin,$quest_max_paladin);
				if($kingdom_sponsor == TRUE)
				{
					$new_paladin = ($new_paladin * 2);
				}				

				if($new_paladin == 1)
				{
					$report_rewards[23] = $new_paladin.' '.$user->lang['PALADIN'];
				}else{
					$report_rewards[23] = number_format($new_paladin).' '.$user->lang['PALADINS'];
				}			
			}			

			$quest_min_dragon_knights = $questdata['quest_min_dragon_knights'];
			$quest_max_dragon_knights = $questdata['quest_max_dragon_knights'];
			if($quest_max_dragon_knights > 0)
			{
				$new_dragon_knights .= rand($quest_min_dragon_knights,$quest_max_dragon_knights);
				if($kingdom_sponsor == TRUE)
				{
					$new_dragon_knights = ($new_dragon_knights * 2);
				}				

				if($new_dragon_knights == 1)
				{
					$report_rewards[24] = $new_dragon_knights.' '.$user->lang['DRAGON_KNIGHT'];
				}else{
					$report_rewards[24] = number_format($new_dragon_knights).' '.$user->lang['DRAGON_KNIGHTS'];
				}			
			}			

			$quest_min_rams = $questdata['quest_min_rams'];
			$quest_max_rams = $questdata['quest_max_rams'];
			if($quest_max_rams > 0)
			{
				$new_rams .= rand($quest_min_rams,$quest_max_rams);
				if($kingdom_sponsor == TRUE)
				{
					$new_rams = ($new_rams * 2);
				}				

				if($new_rams == 1)
				{
					$report_rewards[25] = $new_rams.' '.$user->lang['RAM'];
				}else{
					$report_rewards[25] = number_format($new_rams).' '.$user->lang['RAMS'];
				}			
			}				

			$quest_min_catapults = $questdata['quest_min_catapults'];
			$quest_max_catapults = $questdata['quest_max_catapults'];
			if($quest_max_catapults > 0)
			{
				$new_catapults .= rand($quest_min_catapults,$quest_max_catapults);
				if($kingdom_sponsor == TRUE)
				{
					$new_catapults = ($new_catapults * 2);
				}				

				if($new_catapults == 1)
				{
					$report_rewards[26] = $new_catapults.' '.$user->lang['CATAPULT'];
				}else{
					$report_rewards[26] = number_format($new_catapults).' '.$user->lang['CATAPULTS'];
				}			
			}			

			$quest_min_heavy_catapults = $questdata['quest_min_heavy_catapults'];
			$quest_max_heavy_catapults = $questdata['quest_max_heavy_catapults'];
			if($quest_max_heavy_catapults > 0)
			{
				$new_heavy_catapults .= rand($quest_min_heavy_catapults,$quest_max_heavy_catapults);
				if($kingdom_sponsor == TRUE)
				{
					$new_heavy_catapults = ($new_heavy_catapults * 2);
				}				

				if($new_heavy_catapults == 1)
				{
					$report_rewards[27] = $new_heavy_catapults.' '.$user->lang['HEAVY_CATAPULT'];
				}else{
					$report_rewards[27] = number_format($new_heavy_catapults).' '.$user->lang['HEAVY_CATAPULTS'];
				}			
			}			

			$quest_min_ballistas = $questdata['quest_min_ballistas'];
			$quest_max_ballistas = $questdata['quest_max_ballistas'];
			if($quest_max_ballistas > 0)
			{
				$new_ballistas .= rand($quest_min_ballistas,$quest_max_ballistas);
				if($kingdom_sponsor == TRUE)
				{
					$new_ballistas = ($new_ballistas * 2);
				}				

				if($new_ballistas == 1)
				{
					$report_rewards[28] = $new_ballistas.' '.$user->lang['BALLISTA'];
				}else{
					$report_rewards[28] = number_format($new_ballistas).' '.$user->lang['BALLISTAS'];
				}			
			}			

			$quest_min_trebuchets = $questdata['quest_min_trebuchets'];
			$quest_max_trebuchets = $questdata['quest_max_trebuchets'];
			if($quest_max_trebuchets > 0)
			{
				$new_trebuchets .= rand($quest_min_trebuchets,$quest_max_trebuchets);
				if($kingdom_sponsor == TRUE)
				{
					$new_trebuchets = ($new_trebuchets * 2);
				}				

				if($new_trebuchets == 1)
				{
					$report_rewards[29] = $new_trebuchets.' '.$user->lang['TREBUCHET'];
				}else{
					$report_rewards[29] = number_format($new_trebuchets).' '.$user->lang['TREBUCHETS'];
				}			
			}			

			$quest_min_chimeras = $questdata['quest_min_chimeras'];
			$quest_max_chimeras = $questdata['quest_max_chimeras'];
			if($quest_max_chimeras > 0)
			{
				$new_chimeras .= rand($quest_min_chimeras,$quest_max_chimeras);
				if($kingdom_sponsor == TRUE)
				{
					$new_chimeras = ($new_chimeras * 2);
				}				

				if($new_chimeras == 1)
				{
					$report_rewards[30] = $new_chimeras.' '.$user->lang['CHIMERA'];
				}else{
					$report_rewards[30] = number_format($new_chimeras).' '.$user->lang['CHIMERAS'];
				}			
			}			

			$quest_min_hydras = $questdata['quest_min_hydras'];
			$quest_max_hydras = $questdata['quest_max_hydras'];
			if($quest_max_hydras > 0)
			{
				$new_hydras .= rand($quest_min_hydras,$quest_max_hydras);
				if($kingdom_sponsor == TRUE)
				{
					$new_hydras = ($new_hydras * 2);
				}				

				if($new_hydras == 1)
				{
					$report_rewards[31] = $new_hydras.' '.$user->lang['HYDRA'];
				}else{
					$report_rewards[31] = number_format($new_hydras).' '.$user->lang['HYDRAS'];
				}			
			}			

			$quest_min_basilisks = $questdata['quest_min_basilisks'];
			$quest_max_basilisks = $questdata['quest_max_basilisks'];
			if($quest_max_basilisks > 0)
			{
				$new_basilisks .= rand($quest_min_basilisks,$quest_max_basilisks);
				if($kingdom_sponsor == TRUE)
				{
					$new_basilisks = ($new_basilisks * 2);
				}				

				if($new_basilisks == 1)
				{
					$report_rewards[32] = $new_basilisks.' '.$user->lang['BASILISK'];
				}else{
					$report_rewards[32] = number_format($new_basilisks).' '.$user->lang['BASILISKS'];
				}			
			}

			$quest_min_wyverns = $questdata['quest_min_wyverns'];
			$quest_max_wyverns = $questdata['quest_max_wyverns'];
			if($quest_max_wyverns > 0)
			{
				$new_wyverns .= rand($quest_min_wyverns,$quest_max_wyverns);
				if($kingdom_sponsor == TRUE)
				{
					$new_wyverns = ($new_wyverns * 2);
				}				

				if($new_wyverns == 1)
				{
					$report_rewards[33] = $new_wyverns.' '.$user->lang['WYVERN'];
				}else{
					$report_rewards[33] = number_format($new_wyverns).' '.$user->lang['WYVERNS'];
				}			
			}			

			$quest_min_leviathans = $questdata['quest_min_leviathans'];
			$quest_max_leviathans = $questdata['quest_max_leviathans'];
			if($quest_max_leviathans > 0)
			{
				$new_leviathans .= rand($quest_min_leviathans,$quest_max_leviathans);
				if($kingdom_sponsor == TRUE)
				{
					$new_leviathans = ($new_leviathans * 2);
				}				

				if($new_leviathans == 1)
				{
					$report_rewards[34] = $new_leviathans.' '.$user->lang['LEVIATHAN'];
				}else{
					$report_rewards[34] = number_format($new_leviathans).' '.$user->lang['LEVIATHANS'];
				}			
			}			

			$quest_min_dragons = $questdata['quest_min_dragons'];
			$quest_max_dragons = $questdata['quest_max_dragons'];
			if($quest_max_dragons > 0)
			{
				$new_dragons .= rand($quest_min_dragons,$quest_max_dragons);
				if($kingdom_sponsor == TRUE)
				{
					$new_dragons = ($new_dragons * 2);
				}				

				if($new_dragons == 1)
				{
					$report_rewards[35] = $new_dragons.' '.$user->lang['DRAGON'];
				}else{
					$report_rewards[35] = number_format($new_dragons).' '.$user->lang['DRAGONS'];
				}			
			}			

			$quest_min_land = $questdata['quest_min_land'];
			$quest_max_land = $questdata['quest_max_land'];
			if($quest_max_farms > 0)
			{
				$new_land .= rand($quest_min_land,$quest_max_land);
				if($kingdom_sponsor == TRUE)
				{
					$new_land = ($new_land * 2);
				}				

				if($new_land == 1)
				{
					$report_rewards[36] = $new_land.' '.$user->lang['UNIT_OF_LAND'];
				}else{
					$report_rewards[36] = number_format($new_land).' '.$user->lang['UNITS_OF_LAND'];
				}			
			}
			
			$quest_min_farms = $questdata['quest_min_farms'];
			$quest_max_farms = $questdata['quest_max_farms'];
			if($quest_max_farms > 0)
			{
				$new_farms .= rand($quest_min_farms,$quest_max_farms);
				if($kingdom_sponsor == TRUE)
				{
					$new_farms = ($new_farms * 2);
				}				

				if($new_farms == 1)
				{
					$report_rewards[37] = $new_farms.' '.$user->lang['FARM'];
				}else{
					$report_rewards[37] = number_format($new_farms).' '.$user->lang['FARMS'];
				}			
			}			
			
			$quest_min_timber_mills = $questdata['quest_min_timber_mills'];
			$quest_max_timber_mills = $questdata['quest_max_timber_mills'];
			if($quest_max_timber_mills > 0)
			{
				$new_timber_mills .= rand($quest_min_timber_mills,$quest_max_timber_mills);
				if($kingdom_sponsor == TRUE)
				{
					$new_timber_mills = ($new_timber_mills * 2);
				}				

				if($new_timber_mills == 1)
				{
					$report_rewards[38] = $new_timber_mills.' '.$user->lang['TIMBER_MILL'];
				}else{
					$report_rewards[38] = number_format($new_timber_mills).' '.$user->lang['TIMBER_MILLS'];
				}			
			}			
			
			$quest_min_iron_mines = $questdata['quest_min_iron_mines'];
			$quest_max_iron_mines = $questdata['quest_max_iron_mines'];
			if($quest_max_iron_mines > 0)
			{
				$new_iron_mines .= rand($quest_min_iron_mines,$quest_max_iron_mines);
				if($kingdom_sponsor == TRUE)
				{
					$new_iron_mines = ($new_iron_mines * 2);
				}				

				if($new_iron_mines == 1)
				{
					$report_rewards[39] = $new_iron_mines.' '.$user->lang['IRON_MINE'];
				}else{
					$report_rewards[39] = number_format($new_iron_mines).' '.$user->lang['IRON_MINES'];
				}			
			}			
			
			$quest_min_gold_mines = $questdata['quest_min_gold_mines'];
			$quest_max_gold_mines = $questdata['quest_max_gold_mines'];
			if($quest_max_gold_mines > 0)
			{
				$new_gold_mines .= rand($quest_min_gold_mines,$quest_max_gold_mines);
				if($kingdom_sponsor == TRUE)
				{
					$new_gold_mines = ($new_gold_mines * 2);
				}				

				if($new_gold_mines == 1)
				{
					$report_rewards[40] = $new_gold_mines.' '.$user->lang['GOLD_MINE'];
				}else{
					$report_rewards[40] = number_format($new_gold_mines).' '.$user->lang['GOLD_MINES'];
				}			
			}									
			
			$quest_min_towers = $questdata['quest_min_towers'];
			$quest_max_towers = $questdata['quest_max_towers'];
			if($quest_max_towers > 0)
			{
				$new_towers .= rand($quest_min_towers,$quest_max_towers);
				if($kingdom_sponsor == TRUE)
				{
					$new_towers = ($new_towers * 2);
				}				

				if($new_towers == 1)
				{
					$report_rewards[41] = $new_towers.' '.$user->lang['TOWER'];
				}else{
					$report_rewards[41] = number_format($new_towers).' '.$user->lang['TOWERS'];
				}			
			}
			
			$quest_min_granaries = $questdata['quest_min_granaries'];
			$quest_max_granaries = $questdata['quest_max_granaries'];
			if($quest_max_granaries > 0)
			{
				$new_granaries .= rand($quest_min_granaries,$quest_max_granaries);
				if($kingdom_sponsor == TRUE)
				{
					$new_granaries = ($new_granaries * 2);
				}				

				if($new_granaries == 1)
				{
					$report_rewards[42] = $new_granaries.' '.$user->lang['GRANARY'];
				}else{
					$report_rewards[42] = number_format($new_granaries).' '.$user->lang['GRANARIES'];
				}			
			}			
			
			$quest_min_woodsheds = $questdata['quest_min_woodsheds'];
			$quest_max_woodsheds = $questdata['quest_max_woodsheds'];
			if($quest_max_woodsheds > 0)
			{
				$new_woodsheds .= rand($quest_min_woodsheds,$quest_max_woodsheds);
				if($kingdom_sponsor == TRUE)
				{
					$new_woodsheds = ($new_woodsheds * 2);
				}				

				if($new_woodsheds == 1)
				{
					$report_rewards[43] = $new_woodsheds.' '.$user->lang['WOOD_SHED'];
				}else{
					$report_rewards[43] = number_format($new_woodsheds).' '.$user->lang['WOOD_SHEDS'];
				}			
			}			
			
			$quest_min_ironpits = $questdata['quest_min_ironpits'];
			$quest_max_ironpits = $questdata['quest_max_ironpits'];
			if($quest_max_ironpits > 0)
			{
				$new_ironpits .= rand($quest_min_ironpits,$quest_max_ironpits);
				if($kingdom_sponsor == TRUE)
				{
					$new_ironpits = ($new_ironpits * 2);
				}				

				if($new_ironpits == 1)
				{
					$report_rewards[44] = $new_ironpits.' '.$user->lang['IRON_PIT'];
				}else{
					$report_rewards[44] = number_format($new_ironpits).' '.$user->lang['IRON_PITS'];
				}			
			}
			
			$quest_min_vaults = $questdata['quest_min_vaults'];
			$quest_max_vaults = $questdata['quest_max_vaults'];
			if($quest_max_vaults > 0)
			{
				$new_vaults .= rand($quest_min_vaults,$quest_max_vaults);
				if($kingdom_sponsor == TRUE)
				{
					$new_vaults = ($new_vaults * 2);
				}				

				if($new_vaults == 1)
				{
					$report_rewards[45] = $new_vaults.' '.$user->lang['VAULT'];
				}else{
					$report_rewards[45] = number_format($new_vaults).' '.$user->lang['VAULT'];
				}			
			}			
			
			
															  
			$count = count($report_rewards);
			if ($count > 0) 
			{
				while (list($num,$msg) = each ($report_rewards)) 
				{
					$i++;
					if ($i == $count && $i != 1){
						$reward_msg = $reward_msg . " and <b>$msg</b>. ";
					}elseif ($i == $count && $i == 1){
						$reward_msg = $reward_msg . "<b>$msg</b>. ";
					}else{
						
						$reward_msg = $reward_msg . " <b>$msg</b>";
						
						if ($i+1 != $count){
							$reward_msg = $reward_msg . ",";
						}
					}
				}
			}else{
				$reward_msg = $user->lang['NOTHING'];
			}
			
			
			$exp_needed = exp_to_next_level($kingdom_level);
			$levelup_report = NULL;
			
		    if(($kingdom_exp + $new_exp)  >= $exp_needed)
			{			
				$db->sql_query(
				"UPDATE " . AOD_KINGDOMS_TABLE ." SET 
				kingdom_level = kingdom_level + 1,
				kingdom_turns = kingdom_turns_max,
				kingdom_stamina = kingdom_stamina_max,
				kingdom_coins = kingdom_coins + 5
				WHERE user_id = $user_id");
				$db->sql_return_on_error(false);
				
				$levelup_report = sprintf($user->lang['LEVELUP_REPORT']);			
			}
						
			
			// Win 
			$db->sql_query(
			"UPDATE " . AOD_KINGDOMS_TABLE ." SET 
			kingdom_villagers = kingdom_villagers +  $new_villagers,
			kingdom_pop = kingdom_pop +  $new_villagers,
			kingdom_gold = kingdom_gold +  $new_gold,
			kingdom_food = kingdom_food +  $new_food,
			kingdom_wood = kingdom_wood +  $new_wood,
			kingdom_iron = kingdom_iron +  $new_iron,
			kingdom_coins = kingdom_coins +  $new_dragoncoins,
			kingdom_exp = kingdom_exp +  $new_exp,
			kingdom_soldiers = kingdom_soldiers + $new_soldiers,
			kingdom_spies = kingdom_spies + $new_spies,
			kingdom_macemen = kingdom_macemen + $new_macemen,
			kingdom_axemen = kingdom_axemen + $new_axemen,
			kingdom_spearmen = kingdom_spearmen + $new_spearmen,
			kingdom_swordsmen = kingdom_swordsmen + $new_swordsmen,
			kingdom_legionnaires = kingdom_legionnaires + $new_legionnaires,
			kingdom_knights = kingdom_knights + $new_knights,
			kingdom_slingers = kingdom_slingers + $new_slingers,
			kingdom_bowmen = kingdom_bowmen + $new_bowmen,
			kingdom_long_bowmen = kingdom_long_bowmen + $new_long_bowmen,
			kingdom_crossbowmen = kingdom_crossbowmen + $new_crossbowmen,
			kingdom_light_sword_cavalry = kingdom_light_sword_cavalry + $new_light_sword_cavalry,
			kingdom_heavy_sword_cavalry = kingdom_heavy_sword_cavalry + $new_heavy_sword_cavalry,
			kingdom_light_archer_cavalry = kingdom_light_archer_cavalry + $new_light_archer_cavalry,
			kingdom_heavy_archer_cavalry = kingdom_heavy_archer_cavalry + $new_heavy_archer_cavalry,
			kingdom_paladin = kingdom_paladin + $new_paladin,
			kingdom_dragon_knights = kingdom_dragon_knights + $new_dragon_knights,
			kingdom_rams = kingdom_rams + $new_rams,
			kingdom_catapults = kingdom_catapults + $new_catapults,
			kingdom_heavy_catapults = kingdom_heavy_catapults + $new_heavy_catapults,
			kingdom_ballistas = kingdom_ballistas + $new_ballistas,
			kingdom_trebuchets = kingdom_trebuchets + $new_trebuchets,
			kingdom_chimeras = kingdom_chimeras + $new_chimeras,
			kingdom_hydras = kingdom_hydras + $new_hydras,
			kingdom_basilisks = kingdom_basilisks + $new_basilisks,
			kingdom_wyverns = kingdom_wyverns + $new_wyverns,
			kingdom_leviathans = kingdom_leviathans + $new_leviathans,
			kingdom_dragons = kingdom_dragons + $new_dragons,
			kingdom_land = kingdom_land + $new_land,
			kingdom_farms = kingdom_farms + $new_farms,
			kingdom_timber_mills = kingdom_timber_mills + $new_timber_mills,
			kingdom_iron_mines = kingdom_iron_mines + $new_iron_mines,
			kingdom_gold_mines = kingdom_gold_mines + $new_gold_mines,
			kingdom_towers = kingdom_towers + $new_towers,
			kingdom_granaries = kingdom_granaries + $new_granaries,
			kingdom_woodsheds = kingdom_woodsheds + $new_woodsheds,
			kingdom_ironpits = kingdom_ironpits + $new_ironpits,
			kingdom_vaults = kingdom_vaults + $new_vaults,			
			kingdom_stamina = kingdom_stamina -  $stamina_req,
			kingdom_gold = kingdom_gold -  $gold_req,
			kingdom_food = kingdom_food -  $food_req,
			kingdom_wood = kingdom_wood -  $wood_req,
			kingdom_iron = kingdom_iron -  $iron_req
			WHERE user_id = $user_id");
			$db->sql_return_on_error(false);
			
			// Make sure to update the kingdoms stats
			set_kingdom_stats($user_id);

			// Build the report
			$report = $levelup_report.$user->lang['SUCCESSFULLY_QUEST'].$reward_msg.sprintf($user->lang['STAMINA_USED'],number_format($stamina_req));
			
			// Log the report in the database
			report_transaction($user_id,$report,'quests.php',$date);
			
			// Now it is time to redirect the user to see the report page so they can see the report
			redirect(append_sid("{$phpbb_root_path}/games/aod/report.$phpEx"));
		
		}else{
			// Lose 
		
			$db->sql_query(
			"UPDATE " . AOD_KINGDOMS_TABLE ." 
			SET kingdom_stamina = kingdom_stamina -  $stamina_req,
			kingdom_gold = kingdom_gold -  $gold_req,
			kingdom_food = kingdom_food -  $food_req,
			kingdom_wood = kingdom_wood -  $wood_req,
			kingdom_iron = kingdom_iron -  $iron_req
			WHERE user_id = $user_id");
			$db->sql_return_on_error(false);

			// Make sure to update the kingdoms stats
			set_kingdom_stats($user_id);

			// Build the report
			$report = $user->lang['UNSUCCESSFULL_QUEST'].sprintf($user->lang['STAMINA_USED'],number_format($stamina_req));
			
			// Log the report in the database
			report_transaction($user_id,$report,'quests.php',$date);
			
			// Now it is time to redirect the user to see the report page so they can see the report
			redirect(append_sid("{$phpbb_root_path}/games/aod/report.$phpEx"));
			
		}
	}	
}


// Build & Include the quest list
include($phpbb_root_path . 'games/aod/questlist.' . $phpEx);

// Display an error messages to the user
if($error_msgs){
	$error_msgs = '<span class="errormsg"><b>'.$error_msgs.'</b></span>';
}

$template->assign_vars(array(
	'PAGINATION'			=>	'<span class="stext">'.generate_pagination($pagination_url, $total_quests, $quests_per_page, $start).'</span>',
	'PAGE_NUMBER'			=>	on_page($total_quests, $quests_per_page, $start),
	)
);

include($phpbb_root_path . 'games/aod/includes/page_header.' . $phpEx);


// Output page
page_header($game_name.' - '.$user->lang['QUESTS']);

$template->set_filenames(array(
	'body' => $templates_path.'quests_body.html')
);

page_footer();
?>